import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
const router = new Router({
  mode: 'hash',
  // mode: 'history',
  base: "./",
  routes: [{
    path: '/',
    name: 'home',
    component: () =>
      import('@/components/index.vue')
  },
  {
    path: '/index',
    name: 'home',
    component: () =>
      import('@/components/index.vue')


  },
  {
    path: "*",
    name: "home",
    component: () =>
      import('@/components/index.vue')
  }
  ]
})
// 全局路由守卫
router.beforeEach((to, from, next) => {
  //store.state.login.status
  if (to.matched.some(m => m.meta.auth)) {
    //console.log(to.matched)
    // 对路由进行验证
    if (localStorage.getItem("user")) {
      // 已经登陆
      next(); // 正常跳转到你设置好的页面
    } else {
      // 未登录则跳转到登陆界面，query:{ Rurl: to.fullPath}表示把当前路由信息传递过去方便登录后跳转回来；
      next({
        path: "/"
      });
      // next()
    }
  } else {
    next();
  }
});
export default router;
